package org.zuma.gradle.springboot.task.oci.docker;

import org.gradle.api.Project;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.bundling.AbstractArchiveTask;

import java.util.function.Supplier;

/**
 * @author Lee
 * @date 2024/9/29 11:44
 */
public class DockerTaskRegister {

    public static <T extends AbstractArchiveTask> void registry(Project project, TaskProvider<T> provider, Supplier<Boolean> enabled) {
        project.getTasks().register("buildImage", BuildImageWithFileTask.class, (buildImage) -> {
            buildImage.dependsOn(provider);
            buildImage.setDescription("Builds an docker image of the application using the output of the bootJar task");
            buildImage.setGroup("docker");
            buildImage.setEnabled(enabled.get());
            buildImage.getJar().set(provider.get().getArchiveFile());
            buildImage.getOutJar().set(provider.get().getArchiveFile());
        });
    }
}
